import featureAbility from '@ohos.ability.featureAbility';
import audio from '@ohos.multimedia.audio';
/*
 * Copyright (c) 2021 Huawei Device Co., Maker-IoT-PD.
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import router from '@ohos.router'
export default {
    data: {
        title: 'World',
        id:"1593763549",
        pwd:"123456789"
    },
    launch() {
        router.replace({
            url: 'pages/result/result',
        });
    },
    onInit() {
        this.title = this.$t('strings.world');
        let context = featureAbility.getContext();
        //音频采集初始化
        var audioStreamInfo = {
            samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_8000,
            channels: audio.AudioChannel.CHANNEL_1,
            sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_U8,
            encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
        }

        var audioCapturerInfo = {
            source: audio.SourceType.SOURCE_TYPE_MIC,
            capturerFlags: 1
        }

        var audioCapturerOptions = {
            streamInfo: audioStreamInfo,
            capturerInfo: audioCapturerInfo
        }
        let that = this;

        audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
            if (err) {
                console.error(`gyf AudioCapturer Created : Error: ${err.message}`);
            }
            else {
                console.info('gyf AudioCapturer Created : Success : SUCCESS');
                that.capturer = data;
            }
        });


        //音频播放初始化
        var audioRendererInfo = {
            content: audio.ContentType.CONTENT_TYPE_SPEECH,
            usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
            rendererFlags: 1
        }

        var audioRendererOptions = {
            streamInfo: audioStreamInfo,
            rendererInfo: audioRendererInfo
        }

        audio.createAudioRenderer(audioRendererOptions).then((data) => {
            this.audioRenderer = data;
            console.info('gyf AudioRenderer Created : Success : Stream Type: SUCCESS');
        }).catch((err) => {
            console.info('gyf AudioRenderer Created : ERROR : '+err.message);
        });

        globalThis = this;

    },
}